home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / cvs-1_3.lha / cvs-1.3 / contrib / pcl-cvs / elib-node.el < prev    next >
Text File  |  1992-04-07  |  3KB  |  90 lines

  1. ;;;; elib-node.el,v 1.2 1992/04/07 20:49:16 berliner Exp
  2. ;;;; This file implements the nodes used in binary trees and
  3. ;;;; doubly linked lists
  4. ;;;;
  5. ;;;; Copyright (C) 1991 Inge Wallin
  6. ;;;;
  7. ;;;; This file is part of the GNU Emacs lisp library, Elib.
  8. ;;;;
  9. ;;;; GNU Elib is free software; you can redistribute it and/or modify
  10. ;;;; it under the terms of the GNU General Public License as published by
  11. ;;;; the Free Software Foundation; either version 1, or (at your option)
  12. ;;;; any later version.
  13. ;;;;
  14. ;;;; GNU Elib is distributed in the hope that it will be useful,
  15. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. ;;;; GNU General Public License for more details.
  18. ;;;;
  19. ;;;; You should have received a copy of the GNU General Public License
  20. ;;;; along with GNU Emacs; see the file COPYING.  If not, write to
  21. ;;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22. ;;;; 
  23. ;;;; Author: Inge Wallin
  24. ;;;; 
  25.  
  26. ;;;
  27. ;;; A node is implemented as an array with three elements, using
  28. ;;; (elt node 0) as the left pointer
  29. ;;; (elt node 1) as the right pointer
  30. ;;; (elt node 2) as the data
  31. ;;;
  32. ;;; Some types of trees, e.g. AVL trees, need bigger nodes, but 
  33. ;;; as long as the first three parts are the left pointer, the 
  34. ;;; right pointer and the data field, these macros can be used.
  35. ;;;
  36.  
  37.  
  38. (provide 'elib-node)
  39.  
  40.  
  41. (defmacro elib-node-create (left right data)
  42.   "Create a tree node from LEFT, RIGHT and DATA."
  43.   (` (vector (, left) (, right) (, data))))
  44.  
  45.  
  46. (defmacro elib-node-left (node)
  47.   "Return the left pointer of NODE."
  48.   (` (aref (, node) 0)))
  49.  
  50.  
  51. (defmacro elib-node-right (node)
  52.   "Return the right pointer of NODE."
  53.   (` (aref (, node) 1)))
  54.  
  55.  
  56. (defmacro elib-node-data (node)
  57.   "Return the data of NODE."
  58.   (` (aref (, node) 2)))
  59.  
  60.  
  61. (defmacro elib-node-set-left (node newleft)
  62.   "Set the left pointer of NODE to NEWLEFT."
  63.   (` (aset (, node) 0 (, newleft))))
  64.  
  65.  
  66. (defmacro elib-node-set-right (node newright)
  67.   "Set the right pointer of NODE to NEWRIGHT."
  68.   (` (aset (, node) 1 (, newright))))
  69.  
  70.  
  71. (defmacro elib-node-set-data (node newdata)
  72.   "Set the data of NODE to NEWDATA."
  73.   (` (aset (, node) 2 (, newdata))))
  74.  
  75.  
  76.  
  77. (defmacro elib-node-branch (node branch)
  78.   "Get value of a branch of a node.
  79. NODE is the node, and BRANCH is the branch.
  80. 0 for left pointer, 1 for right pointer and 2 for the data."
  81.   (` (aref (, node) (, branch))))
  82.  
  83.  
  84. (defmacro elib-node-set-branch (node branch newval)
  85.   "Set value of a branch of a node.
  86. NODE is the node, and BRANCH is the branch.
  87. 0 for left pointer, 1 for the right pointer and 2 for the data.
  88. NEWVAL is new value of the branch."
  89.   (` (aset (, node) (, branch) (, newval))))
  90.